home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
oo123.exe
/
OO123.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1993-03-16
|
28KB
|
831 lines
Unit OO123;
(*
Over the last year we've lurked behind the scenes here, enjoying
the fruits of your labours.
It seemed time to give something back, so here's a unit that will
enable you to create Lotus 1-2-3 V2.x compatible models quickly
and easily via OOP. We use the TurboPower Object Professional
date routines but any julian date routine will work if you change
TDateCell.Init. If you don't have any date routines, just UNDEF
USEDATES.
Here's a simple test program:-
Program Test;
{$N+,E+}
Uses Objects, OO123;
Var P123 : PModel;
PD : PDateCell;
PT : PTextCell;
PN : PNumericCell;
Y : Word;
Begin
P123:=New(PModel, Init('TEST.WK1'));
If P123<>NIL then with P123^ do
Begin
PT:=AddTextCell('..Date..');
AddTextCell('Refce')^.JustRight;
AddTextCell('Amount')^.JustRight;
AddTextCell('Narration');
NewRow;
NewRow;
For Y:=1 to 100 do
Begin
PD:=AddDateCell('1/03/93');
PN:=AddNumericCell(Y);
PN:=AddNumericCell(100.00);
PT:=AddTextCell('This is a narration');
PT:=AddTextCell('');
If PT^.Value<>NIL then DisposeStr(PT^.Value);
PT^.Value:=NewStr('This is cell '+PT^.Reference);
NewRow;
end;
SetColumnWidth(3,30);
SetColumnWidth(4,30);
Save;
Dispose(P123, Done);
end;
end.
PS: If you're wondering why there isn't a type TExpressionCell it's
because I've never figured out expression encoding. There's a simple
workaround: just prefix each expression with a special character
(say '|'), then run the following Lotus 1-2-3 macro:-
------------------------------------------------------------------------
\A {indicate Formula Conversion..}{paneloff}{windowsoff}
/rncHERE~{bs}~
{home}
/rncWORKAREA~{bs}.{end}{home}~
{for WIDTH,1,@cols(WORKAREA),1,LOOP1}
{goto}HERE~
/rndWORKAREA~/rndHERE~
{indicate}
LOOP1 {for HEIGHT,1,@rows(WORKAREA),1,LOOP2}
{right}{up HEIGHT-1}
LOOP2 {if @cellpointer("type")<>"l"}{down}{return}
{if @length(@cellpointer("contents"))=0}/re~/rfr~{down}{return}
{if @left(@cellpointer("contents"),1)<>"|"}{down}{return}
{edit}{home}{del}{del}~
{down}
WIDTH 8
HEIGHT 25
ERRCHECK @code(@cellpointer)
------------------------------------------------------------------------
If you know how to create a TExpressionCell the hard way, and you
wouldn't mind sharing your knowledge, then please feel free to e-mail
us.
Enjoy...
Steve Agnew
CIS 70032,2240
*)
{$D-,S-,R-,L-,N+,E+}
{$DEFINE USEDATES}
INTERFACE
Uses Objects, DOS
{$IFDEF USEDATES} , OpDate {$ENDIF}
;
CONST
fProtected = $80;
fFixed = $00;
fScientific = $10;
fCurrency = $20;
fPercent = $30;
fComma = $40;
fSpecial = $70;
fGeneral = $01;
fDMY = $02;
fDM = $03;
fMY = $04;
fText = $05;
TYPE
PCell = ^TCell;
TCell = Object(TObject)
CellType : Word;
CellLength : Word;
CellFormat : Byte;
CellColumn : Word;
CellRow : Word;
Constructor Init(AType, AColumn, ARow : Word);
Procedure SetFormat(AFormat : Byte);
Procedure Write(Var S : TBufStream); VIRTUAL;
Function Reference: String;
end;
{ -------------------------------------------------------------------- }
PNumericCell = ^TNumericCell;
TNumericCell = Object(TCell)
Value : Double;
Constructor Init(AColumn, ARow : Word; AValue : Double);
Procedure Write(Var S : TBufStream); VIRTUAL;
end;
{ -------------------------------------------------------------------- }
PCurrencyCell = ^TCurrencyCell;
TCurrencyCell = Object(TCell)
Value : Double;
Constructor Init(AColumn, ARow : Word; AValue : Double);
Procedure Write(Var S : TBufStream); VIRTUAL;
end;
{$IFDEF USEDATES}
{ -------------------------------------------------------------------- }
PDateCell = ^TDateCell;
TDateCell = Object(TCell)
Value : Double;
Constructor Init(AColumn, ARow : Word; AValue : String);
Procedure Write(Var S : TBufStream); VIRTUAL;
end;
{$ENDIF}
{ -------------------------------------------------------------------- }
PTextCell = ^TTextCell;
TTextCell = Object(TCell)
Just : Char;
Value : PString;
Constructor Init(AColumn, ARow : Word; AValue : String);
Procedure Write(Var S : TBufStream); VIRTUAL;
Procedure JustLeft;
Procedure JustCentre;
Procedure JustRight;
Destructor Done; VIRTUAL;
end;
{ -------------------------------------------------------------------- }
PCellCollection = ^TCellCollection;
TCellCollection = Object(TSortedCollection)
function Compare(Key1, Key2: Pointer): Integer; VIRTUAL;
function FindCell(Col, Row : Word): Pointer;
Procedure Write(Var S: TBufStream); VIRTUAL;
end;
{ -------------------------------------------------------------------- }
ColumnInfo = Record
First : Word;
Last : Word;
Width : Byte;
end;
PModel = ^TModel;
TModel = Object(TObject)
FileName : PathStr;
Cells : PCellCollection;
PRIVATE
MaxRows : Word;
MaxCols : Word;
Row : Word;
Col : Word;
ColHdr : Array[0..255] of ColumnInfo;
PUBLIC
Constructor Init(AFileName : PathStr);
Procedure Save;
Procedure NewRow;
Procedure NewColumn;
Function AddNumericCell (AValue : Double): PNumericCell;
Function AddCurrencyCell (AValue : Double): PCurrencyCell;
{$IFDEF USEDATES}
Function AddDateCell (AValue : String): PDateCell;
{$ENDIF}
Function AddTextCell (AValue : String): PTextCell;
Procedure SetColumnWidth (Column,Width: Word);
Function FindCell(AColumn, ARow : Word): Pointer;
Destructor Done; VIRTUAL;
end;
{ -------------------------------------------------------------------- }
IMPLEMENTATION
Function NumToStr(N: LongInt): String;
Var S : String;
Begin
Str(N,S);
NumToStr:=S;
end;
{ =============================[ TCELL ]============================ }
Constructor TCell.Init(AType, AColumn, ARow : Word);
Begin
If not Inherited Init then FAIL;
CellType := AType;
CellColumn := AColumn;
CellRow := ARow;
CellFormat := $71;
end;
{ -------------------------------------------------------------------- }
Procedure TCell.SetFormat(AFormat : Byte);
Begin
CellFormat := AFormat;
end;
{ -------------------------------------------------------------------- }
Procedure TCell.Write(Var S : TBufStream);
Begin
Abstract;
end;
{ -------------------------------------------------------------------- }
Function TCell.Reference: String;